#include "VN.hpp"

namespace VN{
    GameWindow::~GameWindow(){}
    GameWindow::GameWindow(const char* icon,const char* title,int w,int h,bool resize,bool full,SDL_Color back,Window* parent,SDL_BlendMode mode)
    :Window(icon,title,w,h,resize,full,back,parent,mode){}

    bool GameWindow::_key_down(SDL_Keysym& sym){
        if(game->IsGaming()&&(sym.sym==SDLK_LCTRL||sym.sym==SDLK_RCTRL)){
            game->Skip();
        }
        return false;
    }

    int Main(const char* title,const char* icon_path,const char* start_page,const char* default_language,const char* main_font,initializer_list<SDL_Color> main_color,initializer_list<int> control_size,initializer_list<UIConfig> config,const char* version,SDL_Color default_text_color,const char* main_back_path,
        const char* init_main_back,const char* general_back_path,const char* dialog_back,const char* name_back,
        const char* back_group_name,const char* first_game_back,const char* main_music,SDL_Color time_color,
        initializer_list<ResGroup>
        res_pair,initializer_list<Chapter*> chapters,SaveFunc sf,SaveFunc lf,vector<SDL_Point> control_pos,const char* progress_bg,const char* effect_fg,const char* music_fg){
        frame_delay=1000/30;
        MFInit(20);
        auto w=new Window(icon_path,title,1280,720,false,false,Color::Black);
        auto r=w->renderer;
        auto start=r->LoadTexture(start_page);
        SDL_SetTextureBlendMode(start,SDL_BLENDMODE_BLEND);
        SDL_Rect rect{0,0,1280,720};
        Uint8 c=0;
        r->SetColor({0,0,0,255});
        for(size_t i=0;i<51;i++){
            c+=5;
            SDL_SetTextureAlphaMod(start,c);
            r->Clear();
            r->DrawTexture(0,&rect,start);
            r->Update();
            SDL_Delay(17);
        }
        SDL_DestroyTexture(start);
        auto f=new Font(main_font,24);
        auto g=new GameScene(default_language,f,main_color,control_size,config,version,w,default_text_color,main_back_path,init_main_back,
        general_back_path,dialog_back,name_back,back_group_name,first_game_back,main_music,time_color,
        res_pair,chapters,sf,lf,control_pos,progress_bg,effect_fg,music_fg);
        w->AddControl(g);
        unsigned int delta;
        return MFMain(&delta);
    }
}